package com.takeaway.dao.daolmpl;

import com.takeaway.dao.daointerface.FoodDao;
import com.takeaway.pojo.Food;
import com.takeaway.utils.JdbcUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 后台赖骏
 */
public class FoodDaoImpl implements FoodDao {
    @Override
    public int insert(Food food) throws Exception{
        return JdbcUtils.insert(food);
    }

    @Override
    public int delete(Class<Food> clz, String[] checkField, Object... factor) throws Exception{
        return JdbcUtils.delete(clz,checkField,factor);
    }

    @Override
    public int update(Food food) throws Exception{
        return JdbcUtils.update(food);
    }

    @Override
    public Food selectSingle(Food food, String[] checkFields, Object... factor) throws Exception{
        return (Food) JdbcUtils.selectSingle(food,checkFields,factor);
    }

    @Override
    public ArrayList<Food> selectMore(Class<Food> clz, int begin, int listNum) throws Exception{
        return (ArrayList<Food>) JdbcUtils.selectMore(clz,begin,listNum);
    }

    @Override
    public ArrayList<Food> selectMore(Class<Food> clz, String[] checkField, Object... factor) throws Exception{
        return (ArrayList<Food>) JdbcUtils.selectMore(clz,checkField,factor);
    }
    @Override
    public long selectListNum(int shopId) throws Exception {
        String sql = "select count(*) from Food where shopId ="+shopId;
        return (long)JdbcUtils.executeSelect(sql);
    }

    @Override
    public List<Food> selectListMore(Class<Food> clz, int begin, int listNum, int shopId) throws Exception {
        String sql = "select * from food where shopId ="+shopId+" limit "+begin+" , "+listNum;
        return JdbcUtils.executeSelectList(clz,sql);
    }
    @Override
    public List<Food> selectBookManage(int shopId) throws Exception {
        String sql = "SELECT food.* FROM book,food,`user` " +
                "WHERE foodId = food.id AND shopId = ?" +
                " AND userId = user.id";
        return JdbcUtils.executeSelectList(Food.class, sql , shopId);
    }
}
